import query from './atom/db/query';
import count from './atom/db/count';

declare const action_id: string;
declare const session_id: string;
declare const spaceid: string;

interface Message {
	criteria: object,
	page_size: number,
	page_no: number,
	asc?: string[],
	desc?: string[]
}

async function atom(msg: Message) {
	const systemid = '5981';
	const q = query(action_id, session_id, spaceid, systemid);
	q.prepare('exam_subjects', ['_id', 'exam_subjects_id', 'exam_subjects_name', 'exam_id', 'exam_name', 'fzno', 'course_duration', 'grade', 'total_people', 'department_no', 'department', 'class_name', 'class_id', 'major_no', 'major'], msg.criteria, msg.page_size, msg.page_no, msg.asc, msg.desc);
	const t = await q.exec();
	const c = count(action_id, session_id, spaceid, systemid);
	c.prepare('exam_subjects', msg.criteria);
	const tc = await c.exec();
	return { dataArray: t[0], count: tc[0] };
}
